﻿// JSON C# Class Generator
// http://at-my-window.blogspot.com/?page=json-class-generator

using System;
using Newtonsoft.Json.Linq;
using JsonCSharpClassGenerator;
using TomatoSynchronizer.Store;
using System.Collections;
using System.Collections.Generic;

namespace TomatoSynchronizer.Entities
{

	public class TranslationGroup
	{
		private List<Translation> _translations;
		public List<Translation> Translations {
			get { return _translations; }
			set { _translations = value; }
		}
		
		public TranslationGroup()
		{
		}
		
		public override bool Equals(object obj)
		{
			if(obj is TranslationGroup)
			{
				TranslationGroup group = (TranslationGroup)obj;
				if(group._id == _id && group._text == _text)
				{
					if(group.Translations.Count == _translations.Count)
					{
						foreach(Translation translationSrc in group.Translations)
						{														
							foreach(Translation translationDest in _translations)
							{
								if(!translationSrc.Equals(translationDest))
								{
									return false;
								}								
							}
						}
						
						return true;
					}
				}
			}
			
			return false;
		}

		public TranslationGroup(string json)
			: this(JObject.Parse(json))
		{
		}

		private JObject __jobject;
		public TranslationGroup(JObject obj)
		{
			this.__jobject = obj;
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _id;
		public string id
		{
			get
			{
				if(_id == null)
					_id = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "id"));
				return _id;
			}
			set
			{
				_id = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _text;
		public string text
		{
			get
			{
				if(_text == null)
					_text = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "text"));
				return _text;
			}
			set
			{
				_text = value;
			}
		}

	}
}
